import React, { Component } from 'react'
import Tuijian from './components/tuijian';
import './index.css'
import Adv from './components/adv';
import MainHeader from './components/mainheader';
import withRightNav from '../../components/hoc/withRightNav';
import { CenterPopup } from 'antd-mobile'
import { connect } from 'react-redux';
import { fetchMainData } from '../../store/actions/wzdata';
class Main extends Component {
    constructor() {
        super();
        this.state = {
            tuijianArr: [],
            swiperArr: [],
            recommendList: [],
            daojishiObj: null,
            visible: true
        }

    }
    componentWillUnmount() {
        document.documentElement.scrollTop = 0;
    }
    componentDidMount() {
        // axios.post("https://srv.hotkidceo.com/appapi/api/root-ceo-content/hpPageConfigure/pageList", { "channelId": null, "memberKey": "" }).then(
        //     (res) => {
        //         console.log(res.data.data[5]);
        //         this.setState({
        //             // swiperArr: res.data.data[1].configureAttribute,
        //             list: res.data.data[2].configureAttribute,
        //             // recommendList: res.data.data[10].configureAttributeList
        //             // daojishiObj: res.data.data[5]
        //         })
        //     }
        // )
        this.props.fetchMainData();

    }
    render() {
        // let { list } = this.state;
        let { history, miaoshaObj, swiperList, tuijianList, list } = this.props;
        return (
            <div>
                {swiperList.length !== 0 ? <MainHeader swiperArr={swiperList} list={list} history={history} /> : ""}
                {miaoshaObj != null ? <Adv daojishiObj={miaoshaObj} /> : ''}
                <Tuijian recommendList={tuijianList} ></Tuijian>
                <CenterPopup
                    visible={this.state.visible}
                    onMaskClick={() => {
                        this.setState({
                            visible: false
                        })
                    }}
                >
                    <div className='frameImg'></div>
                    <div className='closeImg' onClick={() => {
                        this.setState({
                            visible: false
                        })
                    }}></div>
                </CenterPopup>
            </div>
        )
    }
}
export default connect(
    state => ({
        tuijianList: state.wzdata.tuijianList || [],
        swiperList: state.wzdata.swiperList || [],
        miaoshaObj: state.wzdata.miaoshaObj || null,
        list: state.wzdata.list || [],
    }),
    { fetchMainData }
)(withRightNav(Main));